package com.cloud.util.other;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;

/**
 * Properties文件操作工具类
 * @author gaof
 * @date 2017年1月24日
 */
public class PropertiesUtil {

	/**
	 * 加载配置文件中的所有配置信息
	 * @param filePath
	 * @return
	 * @throws IOException
	 */
	public static HashMap<String, String> loadAll(String filePath){
		
		Properties prop = new Properties();
		InputStream in = null;
		
		try {
			// 读取属性文件a.properties
			in = new BufferedInputStream(new FileInputStream(filePath));
			prop.load(in);
			
			HashMap<String, String> proMap = new HashMap<String, String>();
			Iterator<String> it = prop.stringPropertyNames().iterator();

			while (it.hasNext()) {
				String key = it.next();
				proMap.put(key, prop.getProperty(key));
			}

			in.close();
			in = null;
			return proMap;
			
		} catch (IOException e) {
			e.printStackTrace();
			
			return null;
			
		}finally{
			
			if(in != null){
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				in = null;
			}
		} 
		
	}
	
}
